const { Types } = require('mongoose')
const mongoose = require('./db')

const shopSchema=new mongoose.Schema({
    name:String,           //店铺名
    shopimg:String,            //店铺头像
    concern:Number,           //关注数
    sold :Number,                //已售
    desc:String,                //店铺描述
    dynamic:[{
       dyimg:String,            //动态图片
       dytext:String,            //动态文字
       thumbs:Number,           //点赞数
    }],
    serve:[
        {
            setname:String,           //服务名
            setdesc:String,            //服务描述
        }
    ],
    commotype:[{
        typename:String,
        commtypes:[String]
    }]
})
//关注店铺
const concernShopSchema=new mongoose.Schema({
    shopid:{
        type:Types.ObjectId,
        ref:'shop'
    }
})
//商品
const commoditySchema = new mongoose.Schema({
    shopid: {
        type: Types.ObjectId,
        ref: 'shop'
    },
    name:String,           //商品名
    price:Number,          //原价
    nowPrice:Number,       //现价
    img:String,            //图片
    sold:Number,           //已售
    type:String,           //类型
    imgs:[String],            //轮播图
    desc:String,           //描述
    pl:[{
        plimg:String,            //评论头像
        plname:String,           //评论人
        plcontent:String,        //评论内容
        pltime:String,           //评论时间
        thumbs:Number,         //点赞数
        plimgs:[String],           //评论图片
        hf:[{
            hfimg:String,            //回复头像
            hfname:String,           //回复人
            hfcontent:String,        //回复内容
            hftime:String,           //回复时间
        }]
    }]

})
//购物车
const ShoppingCartSchema=new mongoose.Schema({
    commodity:[
        {
            commodityid:{
                type:Types.ObjectId,
                ref:'commoditiey'
            },
            num:Number
        }
    ]
})
const TypeSchema = new mongoose.Schema({
    name: String
})

let UserSchema = new mongoose.Schema({
    phone: String,
    pass: String
})

let GongSchema = new mongoose.Schema({
    name: String,
    dizhi: String,
    img: String,
    dian: String,
    shijian:
    {
        type: Date,
        default: Date.now
    },
    chuan: String,
    jian: String
})
const ContentSchema = new mongoose.Schema({
    name: String,
    tab: String,
    img1: String,
    img2: String,
    type: String,
    content1: String,
    content2: String,
    content3: String,
})
const SearchSchema = new mongoose.Schema({
    name: String
})

const FeiSchema = new mongoose.Schema({
    name: String,
    time: String,
    img1: String,
    img2: String,
    content1: String,
    content2: String
})

const PeopleSchema = new mongoose.Schema({
    type: String,
    name: String,
    types: String,
    hao: String,
    phone: String
})
const TypeModel = mongoose.model('type', TypeSchema, 'type')
const ContentModel = mongoose.model('content', ContentSchema, 'content')
const SearchModel = mongoose.model('search', SearchSchema, 'search')
const FeiModel = mongoose.model('fei', FeiSchema, 'fei')
const PeopleModel = mongoose.model('people', PeopleSchema, 'people')

const shopModel = mongoose.model('shop', shopSchema, 'shops')
const commodityModel = mongoose.model('commoditiey', commoditySchema, 'commodities')

let UserModel = mongoose.model('user', UserSchema, 'user')
let GongModel = mongoose.model('gong', GongSchema, 'gong')

//订单分类
const order_CateSchema = new mongoose.Schema({
    name: String
})
//订单主表
const order_ListSchema = new mongoose.Schema({
    name: String,
    ordId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'order_CateSche'
    },
    price: String,
    img: String,
    desc: String
})
//地址分类表
const addressCateSchema = new mongoose.Schema({
    name: String
})
//地址主表
const addressSchema = new mongoose.Schema({
    name: String,
    phone: String,
    addres: String,
    adId: {
        type: mongoose.Types.ObjectId,
        ref: 'AddressCate'
    },
    xiaddress: String,
    status: {
        type: Boolean,
        default: false
    }

})

//我的关注 分类表
const guanZhuCateSchema = new mongoose.Schema({
    name: String,
    type: String
})

//我的关注 主表

const guanZhuSchema = new mongoose.Schema({
    name: String,
    gzId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'guanzhucate'
    },

})

//我的动态 分类表

const guanDongCateSchema = new mongoose.Schema({
    name: String
})

//我的动态 主表

const guanDongSchema = new mongoose.Schema({
    name: String,
    gdId: {
        type: mongoose.Types.ObjectId,
        ref: 'guanDongCate'
    },
    content: String,
    time: String,
    img: String,
    ximg: String,

})

//我的预约 分类表
const yuYueCateSchema = new mongoose.Schema({
    name: String
})

//我的预约主表
const yuYueSchema = new mongoose.Schema({
    name: String,
    yyId: {
        type: mongoose.Types.ObjectId,
        ref: 'yueCate'
    },
    content: String,
    time: String,
    img: String,
    status: {
        type: String,
        default: 'daican'
    }

})

//猜灯谜 分类

const caiCateSchema = new mongoose.Schema({
    name: String
})

//猜灯谜主表
const caiListSchema = new mongoose.Schema({
    name: String,
    caId: {
        type: mongoose.Types.ObjectId,
        ref: 'caidingCate'
    },
    chun: String,
    yuan: String,
    desc: String,
})

//社区
const ShequSchema = new mongoose.Schema({
    name: String,
})

//话题
const HuatiSchema = new mongoose.Schema({
    name: String,
})

//帖子
const TieziSchema = new mongoose.Schema({
    username: String,
    content: String,
    time: String,
    img: {
        type: Array,
        default: []
    },
    status: {
        type: Boolean,
        default: false
    },
    zan: Number,
    like: Number,
    pinglun: Number,
    zhuanfa: Number,
    huatiId: {
        type: mongoose.Types.ObjectId,
        ref: 'Huati'
    },
    shequId: {
        type: mongoose.Types.ObjectId,
        ref: 'Shequ'
    }
})

//评论消息
const pinglunContentSchema = new mongoose.Schema({
    name: String,
    content: String,
    time: String,
    img: String,
    level: Number,
    pid: {
        type: mongoose.Types.ObjectId,
        ref: 'pinglunContent'
    },
    tieziId: {
        type: mongoose.Types.ObjectId,
        ref: 'Tiezi'
    }
})

const eventSchema = new mongoose.Schema({
    name: String,
    img: String,
    desc: String,
    type: String,
    time: String,
    address: String,
    detail: [String]
})

const eventModel = mongoose.model('Event', eventSchema)
const ShequModel = mongoose.model('Shequ', ShequSchema)
const HuatiModel = mongoose.model('Huati', HuatiSchema)
const TieziModel = mongoose.model('Tiezi', TieziSchema)
const pinglunContentModel = mongoose.model('pinglunContent', pinglunContentSchema)

const caiListModel = mongoose.model('caiList',caiListSchema)
const caiCateModel = mongoose.model('caidingCate',caiCateSchema)
const yuYueModel = mongoose.model('yueyue',yuYueSchema)
const yuYueCateModel = mongoose.model('yueCate',yuYueCateSchema)
const guanDongModel = mongoose.model('guanDong',guanDongSchema)
const guanDongCateModel = mongoose.model('guanDongCate',guanDongCateSchema)
const guanZhuModel = mongoose.model('guanzhu',guanZhuSchema)
const guanZhuCateModel = mongoose.model('guanzhucate',guanZhuCateSchema)
const addressModel = mongoose.model('address',addressSchema)
const addressCateModel = mongoose.model('AddressCate',addressCateSchema)
const order_ListModel = mongoose.model('order_List',order_ListSchema)
const order_CateModel = mongoose.model('order_CateSche',order_CateSchema)// 订单子表
const concernShopModel = mongoose.model('concernShop',concernShopSchema)
const ShoppingCartModel = mongoose.model('ShoppingCart',ShoppingCartSchema)

module.exports = {
    TypeModel,
    ContentModel,
    SearchModel,
    FeiModel,
    PeopleModel,
    order_CateModel,
    order_ListModel,
    addressCateModel,
    addressModel,
    guanZhuModel,
    guanZhuCateModel,
    guanDongCateModel,
    guanDongModel,
    yuYueCateModel,
    yuYueModel,
    caiCateModel,
    caiListModel,
    shopModel,
    commodityModel,
    ShequModel,
    HuatiModel,
    TieziModel,
    pinglunContentModel,
    concernShopModel,
    ShoppingCartModel,
    UserModel,
    GongModel,
    eventModel,
}
